﻿using BCCommon;
using BCDto.TMS.User.UserAddressBook;
using BCService.TMS.User.UserAddressBook;
using BCTMSRESTful.Configs;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace BCTMSRESTful.Controllers.ClientApp.User
{
    /// <summary>
    /// 用户地址薄
    /// </summary>
    [ApiExplorerSettings(GroupName = "ClientApp")]
    [Route("api/v1/ClientApp/[controller]")]
    public class UserAddressBookController : ClientAppBaseController
    {
        #region 
        private IUserAddressBookService userAddressBookService;
        #endregion

        #region 构造函数
        /// <summary>
        /// 构造函数
        /// </summary> 
        public UserAddressBookController(IUserAddressBookService userAddressBookService)
        {
            this.userAddressBookService = userAddressBookService;
        }
        #endregion

        #region POST 添加  
        /// <summary>
        /// 添加新用户地址薄
        /// </summary>
        /// <param name="dto">用户地址薄数据模型</param>
        /// <response code="201">添加新用户地址薄</response>
        /// <returns></returns>
        [Log("添加新用户地址薄")]
        [HttpPost]
        [ProducesResponseType(typeof(UserAddressBookDto), 201)]
        public IActionResult Post([FromBody] UserAddressBookRequestDto dto)
        {
            var result = this.userAddressBookService.Add(dto, this.UserInfo);
            return Ok(result);
        }

        #endregion

        #region PUT 修改   
        /// <summary>
        /// 修改用户地址薄
        /// </summary>
        /// <param name="userAddressBookId">用户地址薄Id</param>
        /// <param name="dto">用户地址薄数据模型</param>
        /// <response code="200">修改用户地址薄</response>
        /// <returns></returns>
        [Log("修改用户地址薄")]
        [HttpPut("{user_address_book_id}")]
        [ProducesResponseType(typeof(UserAddressBookDto), 200)]
        public IActionResult Put([FromRoute(Name = "user_address_book_id")]long userAddressBookId,
            [FromBody] UserAddressBookRequestDto dto)
        {
            var result = this.userAddressBookService.Update(dto, userAddressBookId, this.UserInfo);
            return this.Ok(result);
        }
        #endregion

        #region 删除  
        /// <summary>
        /// 删除用户地址薄
        /// </summary>
        /// <param name="userAddressBookId">用户地址薄ID</param>
        /// <response code="204">删除用户地址薄</response>
        /// <returns></returns>
        [Log("删除用户地址薄纪录")]
        [HttpDelete("{user_address_book_id}")]
        [ProducesResponseType(typeof(NoContentResult), 204)]
        public IActionResult Delete([FromRoute(Name = "user_address_book_id")] long userAddressBookId)
        {
            this.userAddressBookService.Delete(this.UserInfo, userAddressBookId);
            return NoContent();
        }
        #endregion

        #region GetByID     
        /// <summary>
        /// 获取一条用户地址薄
        /// </summary>
        /// <param name="userAddressBookId">用户地址薄ID</param>
        /// <response code="200">获取一条用户地址薄</response>
        /// <returns></returns>
        [HttpGet("{user_address_book_id}")]
        [ProducesResponseType(typeof(UserAddressBookViewDto), 200)]
        public IActionResult Get([FromRoute(Name = "user_address_book_id")] long userAddressBookId)
        {
            var result = this.userAddressBookService.GetById(userAddressBookId);
            return this.Ok(result);
        }
        #endregion

        #region Query 
        /// <summary>
        /// 查询用户地址薄
        /// </summary>
        /// <param name="pageIndex">页号</param>
        /// <param name="pageSize">每页数据条数</param>
        /// <response code="200">查询用户地址薄</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<UserAddressBookViewDto>), 200)]
        public IActionResult Query([FromQuery(Name = "page_index")] int pageIndex = 1, 
            [FromQuery(Name = "page_size")] int pageSize = 10)
        {
            var result = this.userAddressBookService.Query(this.UserInfo, pageIndex, pageSize);
            return this.Ok(result);
        }
        #endregion

        #region List 
        /// <summary>
        /// 获取用户地址薄列表
        /// </summary>
        /// <response code="200">获取用户地址薄列表</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(IEnumerable<UserAddressBookViewDto>), 200)]
        public IActionResult List()
        {
            var result = this.userAddressBookService.GetList(this.UserInfo);
            return this.Ok(result);
        }
        #endregion
    }
}
